import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import list from './src/list.json';

//批量生成跨域配置
function forproxy(list) {
    let obj = {};
    list.forEach(item => {
        obj[item.proxy] = {
            target: new URL(item.url).origin,
            changeOrigin: true,
            rewrite: (path) => path.replace(RegExp(`^${item.proxy}`), "")
        }
    })
    return obj;
}

export default defineConfig(({ mode }) => {
    console.log(mode);
    return {
        plugins: [react()],
        server: {
            proxy: {
                ...forproxy(list),
                "/bing": {
                    target: "https://cn.bing.com",
                    changeOrigin: true,
                    rewrite: (path) => path.replace(RegExp(`^/bing`), "")
                },
            }
        }
    }
})